package com.nineclock.sign.controller;

import com.nineclock.common.entity.PageResult;
import com.nineclock.common.entity.Result;
import com.nineclock.sign.dto.SignPageDTO;
import com.nineclock.sign.pojo.SignInfo;
import com.nineclock.sign.dto.SignAndDepartmentDTO;
import com.nineclock.sign.dto.SignDTO;
import com.nineclock.sign.dto.SignInfoDTO;
import com.nineclock.sign.service.SignInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping
@Api(value = "签到管理接口", tags = "签到服务")
public class SignController {

    @Autowired
    private SignInfoService signInfoService;


    /**
     * 查询签到列表
     * 接口路径：GET
     */
    @GetMapping("/sign")
    @ApiOperation("查询签到列表")
    public Result<PageResult<SignPageDTO>> querySignPage(@RequestParam String startTime,
                                                         @RequestParam String endTime,
                                                         @RequestParam Integer page,
                                                         @RequestParam Integer pageSize){
        PageResult<SignPageDTO> pageResult = signInfoService.querySignPage(startTime,endTime,page,pageSize);
        return Result.success(pageResult);
    }

    /**
     * 导出签到列表
     * 接口路径：GET/export
     */
    @GetMapping("/export")
    @ApiOperation("导出签到列表")
    public void exportSignPage(@RequestParam String startTime, @RequestParam String endTime) throws IOException {
        signInfoService.exportSignList(startTime, endTime);
    }


    /**
     * 接口名称：APP:签到
     * 接口路径：POST/sign/insert
     */
    @ApiOperation("APP: 签到")
    @PostMapping("insert")
    public Result insert(@RequestParam Map map) {
        signInfoService.insert(map);

        return Result.success();
    }

    /**
     * 接口名称：APP: 获取当前用户当天签到次数
     * 接口路径：GET/sign/getDayCount
     */

    @ApiOperation("APP: 获取当前用户当天签到次数")
    @GetMapping("/getDayCount")
    public Result<Integer> getDayCount() {
        Integer count = signInfoService.getDayCount();
        return Result.success(count);
    }

    /**
     * 接口名称：APP: 获取团队员工打卡列表
     * 接口路径：GET/sign/listSignAllUser
     */

    @ApiOperation("APP: 获取团队员工打卡列表")
    @GetMapping("listSignAllUser")
    public Result<List<SignDTO>> listSignAllUser(@RequestParam String dateStr) {
        List<SignDTO> signDTOList = signInfoService.listSignAllUser(dateStr);
        return Result.success(signDTOList);
    }

    /**
     * 查询本月签到记录
     * 接口路径：GET/sign/pagingSignCurrentUserByMonth
     */
    @GetMapping("pagingSignCurrentUserByMonth")
    @ApiOperation("查询本月签到记录")
    public Result<List<SignInfoDTO>> pagingSignCurrentUserByMonth(String dateStr) {
        List<SignInfoDTO> signInfoDTOList = signInfoService.pagingSignCurrentUserByMonth(dateStr);
        return Result.success(signInfoDTOList);
    }
}
